package curd

import "fmt"

// ProFormText
func GenText(mf ModelField) string {
	const ctrlTmpl = `
      <ProFormText
        name="%s"
        label="%s"%s
      />`
	const rulesTmpl = `
        rules={[{ required: true, message: '%s' }]}`

	if mf.IsPageRequired {
		rules := fmt.Sprintf(rulesTmpl, mf.PageRequireMsg)
		return fmt.Sprintf(ctrlTmpl, mf.Name, mf.Title, rules)
	}

	return fmt.Sprintf(ctrlTmpl, mf.Name, mf.Title, "")
}

// ProFormRadio
func GenRadio(mf ModelField) string {
	const ctrlTmpl = `
      <ProFormRadio.Group
        name="%s"
        label="%s"
        options={[
          { label: '选项1', value: 1 },
          { label: '选项2', value: 2 },
        ]}%s
      />`
	const rulesTmpl = `
        rules={[{ required: true, message: '%s' }]}`

	if mf.IsPageRequired {
		rules := fmt.Sprintf(rulesTmpl, mf.PageRequireMsg)
		return fmt.Sprintf(ctrlTmpl, mf.Name, mf.Title, rules)
	}

	return fmt.Sprintf(ctrlTmpl, mf.Name, mf.Title, "")
}
